﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using JavaSubstitutes;

namespace Sprites
{
	public class FlowerEnemy : Enemy
	{
		private int tickCount;
		private int yStart;
		private int jumpTime = 0;
		private LevelScene world;

		public FlowerEnemy(LevelScene world, int x, int y): base(world, x, y, 1, ENEMY_SPIKY, false)
		{
			//super(world, destX, destY, 1, ENEMY_SPIKY, false);

			noFireballDeath = false;
			this.world = world;
			this.xPic = 0;
			this.yPic = 6;
			this.yPicO = 24;
			this.height = 12;
			this.width = 2;

			yStart = y;
			yDelta = -8;

			this.y -= 1;

			this.layer = 0;

			for (int i = 0; i < 4; i++)
			{
				move();
			}
		}

		public override void move()
		{
			if (deadTime > 0)
			{
				deadTime--;

				if (deadTime == 0)
				{
					deadTime = 1;
					for (int i = 0; i < 8; i++)
					{
						world.addSprite(new Sparkle((int)(x + RandomExtensions.random() * 16 - 8) + 4, (int)(y - RandomExtensions.random() * 8) + 4, (double)(RandomExtensions.random() * 2 - 1), (double)RandomExtensions.random() * -1, 0, 1, 5));
					}
					spriteContext.removeSprite(this);
				}

				x += xDelta;
				y += yDelta;
				yDelta *= 0.95f;
				yDelta += 1;

				return;
			}

			tickCount++;

			if (y >= yStart)
			{
				y = yStart;

				int xd = (int)(Math.Abs(world.mario.x - x));
				jumpTime++;
				if (jumpTime > 40 && xd > 24)
				{
					yDelta = -8;
				}
				else
				{
					yDelta = 0;
				}
			}
			else
			{
				jumpTime = 0;
			}

			y += yDelta;
			yDelta *= 0.9f;
			yDelta += 0.1f;

			xPic = ((tickCount / 2) & 1) * 2 + ((tickCount / 6) & 1);
		}

		/*    public void render(Graphics og, double alpha)
			{
				if (!visible) return;
        
				int xPixel = (int)(xOld+(destX-xOld)*alpha)-xPicO;
				int yPixel = (int)(yOld+(destY-yOld)*alpha)-yPicO;

				int a = ((tick/3)&1)*2;
		//        a += ((tick/8)&1);
				og.drawImage(sheet[a*2+0,6], xPixel-8, yPixel+8, 16, 32, null);
				og.drawImage(sheet[a*2+1,6], xPixel+8, yPixel+8, 16, 32, null);
			}*/
	}
}